package org.acghub.json;

import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.JsonObject;
import org.bson.BsonDocument;
import org.bson.Document;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class User  implements MultiMarshal {
    private Long id;
    private String name;
    private String email;
    private List<Pet> petList;
    private Set<String> tags;
    private Map<Integer, Pet> petMap;
    private LocalDateTime birthday;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<Pet> petList() {
        return petList;
    }

    public void petList(List<Pet> petList) {
        this.petList = petList;
    }

    public List<Pet> getPetList() {
        return petList;
    }

    public void setPetList(List<Pet> petList) {
        this.petList = petList;
    }

    public LocalDateTime getBirthday() {
        return birthday;
    }

    public void setBirthday(LocalDateTime birthday) {
        this.birthday = birthday;
    }

    public Set<String> getTags() {
        return tags;
    }

    public void setTags(Set<String> tags) {
        this.tags = tags;
    }

    public Map<Integer, Pet> getPetMap() {
        return petMap;
    }

    public void setPetMap(Map<Integer, Pet> petMap) {
        this.petMap = petMap;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(id, user.id) && Objects.equals(name, user.name) && Objects.equals(email, user.email) && Objects.equals(petList, user.petList) && Objects.equals(birthday, user.birthday);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, email, petList, birthday);
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", email='" + email + '\'' +
                ", petList=" + petList +
                ", tags=" + tags +
                ", petMap=" + petMap +
                ", birthday=" + birthday +
                '}';
    }

    public Document marshal(Document writeDoc) {


        return null;
    }

    public void unmarshal(Document readDoc) {
        if (readDoc.containsKey("id")) {
            this.id = readDoc.getLong("id");
        }
        if (readDoc.containsKey("name")) {
            this.name = readDoc.getString("name");
        }
        if (readDoc.containsKey("email")) {
            this.email = readDoc.getString("email");
        }
        if (readDoc.containsKey("petList")) {
            List<Document> petListReadDoc = readDoc.getList("petList", Document.class);
            for (Document doc : petListReadDoc) {
                Pet pet = new Pet();
                pet.unmarshal(doc);
                this.petList.add(pet);
            }
        }
    }

    @Override
    public BsonDocument marshal(BsonDocument writer) {
        return null;
    }

    @Override
    public void unmarshal(BsonDocument reader) {

    }

    @Override
    public JSONObject marshal(JSONObject writer) {
        return null;
    }

    @Override
    public void unmarshal(JSONObject reader) {

    }

    @Override
    public ObjectNode marshal(ObjectNode writer) {
        return null;
    }

    @Override
    public void unmarshal(ObjectNode reader) {

    }

    @Override
    public JsonObject marshal(JsonObject writer) {
        return null;
    }

    @Override
    public void unmarshal(JsonObject reader) {

    }
}
